package com.ihelp.rest.mis.platform.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ihelp.rest.mis.platform.service.RoleService;
import com.ihelp.rest.mis.pojo.Role;
import com.ihelp.rest.utils.HtmlUtil;

/**
 * 角色管理
*      
* 类名称：RoleController   
* 类描述：     
* 创建时间：2013-3-13 下午04:26:11    
* 备注：   
* @version
 */
@Controller
@RequestMapping("/system/role")
public class RoleController {

	@Autowired
	private RoleService roleService;
	
	@RequestMapping("loadRolePage.do")
	public String loadRolePage(){
		return "system/role/role";
	}
	
	/**
	 * 查询所有角色列表JSON数据
	 * @param response
	 */
	@RequestMapping("findRoles.do")
	public void findRoles(HttpServletResponse response){
		String json = this.roleService.findRoles();
		HtmlUtil.writerJson(response, json);
	}
	
	/**
	 * 角色下拉列表JSON 数据
	 * @param response
	 */
	@RequestMapping("findRolesComJson.do")
	public void findRolesComJson(HttpServletResponse response){
		String json = this.roleService.findRolesComJson();
		HtmlUtil.writerJson(response, json);
	}
	
	/**
	 * 加载角色添加页面
	 * @return
	 */
	@RequestMapping("loadAddRolePage.do")
	public String loadAddRolePage(HttpServletRequest request, String uuid){
		request.setAttribute("Role", this.roleService.getRole(uuid));
		return "system/role/addRole";
	}
	
	/**
	 * 新增和修改角色
	 * @param response
	 * @param role
	 * @param moduleArr
	 */
	@RequestMapping("addRole.do")
	public void addRole(HttpServletResponse response, Role role, String moduleArr){
		String text = this.roleService.saveRole(role, moduleArr);
		HtmlUtil.writerText(response, text);
	}
	
	/**
	 * 删除角色
	 * @param response
	 * @param module
	 */
	@RequestMapping("delRole.do")
	public void delRole(HttpServletResponse response, Role role){
		String text = this.roleService.delRole(role);
		HtmlUtil.writerText(response, text);
	}
	
}
